package com.hbvtc.xxxy.nikeSale.frames;

import java.awt.Font;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextField;

import com.hbvtc.xxxy.nikeSale.daos.Vipdao;
import com.hbvtc.xxxy.nikeSale.utils.DbManager;

/*
 * 删除会员的信息
 */
public class DelVipNike extends JFrame {
	Connection con;
	PreparedStatement pre;
	String sql;
	JLabel jLabel1, jLabel2;
	JTextField jTextField1, jTextField2;
	JPanel jPanel;
	JButton jButton1;

	public DelVipNike() {
		this.setTitle("会员删除界面");
		this.setSize(1000, 700);
		this.setLocationRelativeTo(null);
		this.setVisible(true);
		// 设置标题栏的图标
		ImageIcon imageIcon = new ImageIcon(getClass().getResource("01.png"));
		this.setIconImage(imageIcon.getImage());
		String path = "images/001.jpg";
		ImageIcon background = new ImageIcon(path);
		JLabel label = new JLabel(background);
		label.setBounds(0, 0, this.getWidth(), this.getHeight());
		JPanel imagePanel = (JPanel) this.getContentPane();
		imagePanel.setOpaque(false);
		this.getLayeredPane().add(label, new Integer(Integer.MIN_VALUE));
	
		this.setLayout(null);
		jTextField1 = new JTextField();
		jTextField2 = new JTextField();
		jLabel1 = new JLabel("会员电话:");
		jLabel2 = new JLabel("会员密码:");
		jButton1 = new JButton("删除");
		this.add(jButton1);
		this.add(jTextField1);
		this.add(jTextField2);
		this.add(jLabel1);
		this.add(jLabel2);

		jLabel1.setBounds(200, 200, 150, 40);
		jLabel1.setFont(new Font(null, 0, 24));
		jTextField1.setBounds(350, 200, 280, 40);
		jTextField1.setFont(new Font(null, 0, 24));
		jLabel2.setBounds(200, 400, 150, 40);
		jLabel2.setFont(new Font(null, 0, 24));
		jTextField2.setBounds(350, 400, 280, 40);
		jTextField2.setFont(new Font(null, 0, 24));
		jButton1.setBounds(650, 550, 150, 40);
		jButton1.setFont(new Font(null, 0, 24));
		jButton1.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				int n = JOptionPane.showConfirmDialog(null, "确认删除吗?", "确认删除框",
						JOptionPane.YES_NO_CANCEL_OPTION);
				if (n == JOptionPane.YES_OPTION) {
					String id = jTextField1.getText().trim();
					String pwd = jTextField2.getText().trim();
					Vipdao vipdao = new Vipdao();
					con = DbManager.getconn();
					sql = "delete from vip where telephone=? and pwd=?";
					try {
						pre = con.prepareStatement(sql);
						pre.setString(1, id);
						pre.setString(2, pwd);
						if (vipdao.sss(id) == true) {
							pre.execute();
							JOptionPane.showMessageDialog(DelVipNike.this,
									"删除会员成功");
						} else {
							JOptionPane.showMessageDialog(DelVipNike.this,
									"删除会员失败");
						}
					} catch (Exception e1) {
						// TODO: handle exception
					}
				}
				if (n == JOptionPane.NO_OPTION) {
					System.exit(0);
				}
			}
		});
	}

	public static void main(String[] args) {
		new DelVipNike().setVisible(true);
	}
}
